package mycompany.model.chat;

import mycompany.model.UserBaseModel;
import mycompany.model.message.PrivateMessageModel;

/**
 * Represents simple chat model
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 */
public class ChatSimpleModel <U extends UserBaseModel> extends AbstractChatModel {
    
    /**
     * Constructs an instance
     * @param id defines chat id
     * @param ownerId defines user id which creates that chat
     */
    public ChatSimpleModel(UserBaseModel owner, int historyLength, int maxUsersCount){
        super(owner, historyLength, maxUsersCount);
    }

    public String getPartnerName(U me){
        for(Object entry : users){
            U user = (U)entry;
            if(!user.equals(me)) return user.getName();
        }
        return null;
    }

    @Override
    public void addMessage(UserBaseModel user, String text) {
        PrivateMessageModel message = new PrivateMessageModel(getNextMessageId(), text, user);
        addMessageToList(message, user);
    }
}
